package krow.dev.gunpobus.util;

public class CastUtil {
	
	public static final int toInteger(String value){
		try {
			return Integer.valueOf(value);
		} catch (Exception e) {
			return 0;
		}
	}
	
	public static final int toInteger(String value, int defaultValue){
		try {
			return Integer.valueOf(value);
		} catch (Exception e) {
			return defaultValue;
		}
	}
	
	public static final long toLong(String value){
		try {
			return Long.valueOf(value);
		} catch (Exception e) {
			return 0;
		}
	}
	
	public static final Float toFloat(String value){
		try {
			return Float.valueOf(value);
		} catch (Exception e) {
			return 0F;
		}
	}
	
	public static final Double toDouble(String value){
		try {
			return Double.valueOf(value);
		} catch (Exception e) {
			return 0D;
		}
	}
	
	public static final Boolean toBoolean(String value){
		try {
			return Boolean.valueOf(value);
		} catch (Exception e) {
			return false;
		}
	}
	
	public static final Boolean toBoolean(int value){
		if(value == 0){
			return false;
		}else{
			return true;
		}
	}
	
	public static boolean isInteger(String value) {
        try {
            Integer.parseInt(value);
            return true;
        } catch (Exception e) {
        	
        }
        return false;
    }
}
